﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using AqueleAjax.UI;

namespace AqueleAjax.UI.Controls
{
    public class AutoCompleteResultItem : RepeaterItem
    {
        private Control _namingContainer;

        public override Control NamingContainer
        {
            get
            {
                return this._namingContainer;
            }
        }

        private ControlCollection _controls;

        public override ControlCollection Controls
        {
            get
            {
                return this._controls;
            }
        }

        public AutoCompleteResultItem(RepeaterItem item)
            : base(item.ItemIndex, item.ItemType)
        {
            this.DataItem = item.DataItem;
            this.EnableTheming = item.EnableTheming;
            this.EnableViewState = item.EnableViewState;
            this.ID = item.ID;
            this.Visible = item.Visible;
            
            this.Page = item.Page;
            this.Site = item.Site;
            this.SkinID = item.SkinID;
            this.TemplateControl = item.TemplateControl;

            this._namingContainer = item.NamingContainer;
            this._controls = item.Controls;
        }

        public override Control FindControl(string id)
        {
            Control control = base.FindControl(id);

            if (control == null)
            {
                for (int i = 0; i < this.Controls.Count; i++)
                {
                    if (!string.IsNullOrEmpty(this.Controls[i].ID) && this.Controls[i].ID.Equals(id, StringComparison.OrdinalIgnoreCase))
                    {
                        control = this.Controls[i];
                        break;
                    }
                }
            }

            return control;
        }
    }
}
